<?php 
require_once '../kelas/fungsi.php';
require_once '../kelas/amankanParam.php';
require_once '../kelas/record.php';

require_once '../kelas/kategori.php';
require_once '../kelas/produk.php';
require_once '../kelas/reportTemplate.php';
require_once '../kelas/reports.php';
$dtGet = $objParamAman->getMethod();
$dtPost= $objParamAman->postMethod();
$on = isset($dtGet['on'])?$dtGet['on']:'';
$objFungsi->inisialisasiProses($on);
switch ($on) {
	case 'stokbrg':
	$inKat = (isset($dtPost['idkat']) && count($dtPost['idkat'])>0)?implode(',',$dtPost['idkat']):'';
	$inProd = (isset($dtPost['idproduk']) && count($dtPost['idproduk'])>0)?implode(',',$dtPost['idproduk']):'';
	$condStr ='(';
		$s = '';
		$s .= (strlen($s)>0 && (strlen($inKat)>0 || strlen($inProd)>0) )?' AND ':'';
		$s .= strlen($inKat)>0?' idkategori IN('.$inKat.')':'';
		$s .= (strlen($s)>0 && strlen($inProd)>0)?' AND ':'';
		$s .= strlen($inProd)>0?' id IN('.$inProd.')':'';
		$condStr .=$s;
		$condStr .=')';
$objProduk->namaTabel = 'v_produk';
$cStr = strlen($condStr)>3?$condStr:null;
$objProduk->get('*',null,null,null,'idkategori,nama','ASC',$cStr);
$dataLapStokBrg = $objProduk->execute();

$wtd  = array();
if(strlen($inKat)>0){
	$wtd['Kategori']=$objKategori->getWhereIn('nama','id',$inKat);	
};
if(strlen($inProd)>0){
	$wtd['Produk']=$objProduk->getWhereIn('nama','id',$inProd);
};
echo $objReportTemplate->lapStokBrg($dataLapStokBrg,$wtd);
break;
case 'lapjual':
$dari =date('Y-m-d',strtotime($dtPost['tahunDari'].'-'.$dtPost['bulanDari'].'-'.$dtPost['tglDari']));
$sampai=date('Y-m-d',strtotime($dtPost['tahunSampai'].'-'.$dtPost['bulanSampai'].'-'.$dtPost['tglSampai']));
if($dtPost['status_pesan']=='all'){
	$arrW=array();
	$addTInfo=array('Status Pemesanan'=>'Ditolak, Dalam Proses, Menunggu Pembayaran, Transaksi Selesai');
}
else{
	$arrW = array('status_pesan'=>$dtPost['status_pesan']);		
	$addTInfo=array('Status Pemesanan'=>$dtPost['status_pesan']);
}
$dyt = $objReports->getPenjualan($dari,$sampai,$arrW,null,$objReports);
//echo $objReports->strQuery;
$date=array('from'=>$dari,'to'=>$sampai);
echo $objReportTemplate->lapPenjualan($dyt,$date,$addTInfo,$dtPost['status_pesan']);
break;
default:
echo $objFungsi->redirect(BASEURLADMIN.'?v=report');
break;
}
?>